-
-
Notifications
You must be signed in to change notification settings - Fork 523
[16.0][IMP] queue_job: Add error handler when job fails #734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi @guewen, |
queue_job/models/queue_job.py
Outdated
| raise JobError("Job failed") | ||
|
|
||
| def _call_webhook(self, **kwargs): | ||
| only_if_max_retries_reached = kwargs.get("only_if_max_retries_reached", False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| only_if_max_retries_reached = kwargs.get("only_if_max_retries_reached", False) | |
| only_if_max_retries_reached = kwargs.get("only_if_max_retries_reached") |
queue_job/models/queue_job.py
Outdated
| if only_if_max_retries_reached and (job and job.retry < job.max_retries): | ||
| return | ||
|
|
||
| webhook_url = kwargs.get("webhook_url", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| webhook_url = kwargs.get("webhook_url", None) | |
| webhook_url = kwargs.get("webhook_url") |
queue_job/models/queue_job.py
Outdated
| webhook_url = kwargs.get("webhook_url", None) | ||
| if not webhook_url: | ||
| return | ||
| payload = kwargs.get("payload", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| payload = kwargs.get("payload", None) | |
| payload = kwargs.get("payload") |
test_queue_job/tests/test_job.py
Outdated
| model = self.env["test.queue.job"] | ||
| job = model.with_delay(priority=1, max_retries=1).testing_method() | ||
| trap.assert_jobs_count(1) | ||
| with patch.object(type(job), "perform", side_effect=IOError,), patch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| with patch.object(type(job), "perform", side_effect=IOError,), patch( | |
| with patch.object(type(job), "perform", side_effect=IOError), patch( |
queue_job/job.py
Outdated
| action_kwargs = self.job_config.error_handler_kwargs | ||
| action_kwargs["job"] = self | ||
| action_kwargs["job"] = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate line.
Can also be written as:
| action_kwargs = self.job_config.error_handler_kwargs | |
| action_kwargs["job"] = self | |
| action_kwargs["job"] = self | |
| action_kwargs = {**self.job_config.error_handler_kwargs, "job": self} |
queue_job/models/queue_job.py
Outdated
| def _call_webhook(self, **kwargs): | ||
| only_if_max_retries_reached = kwargs.get("only_if_max_retries_reached", False) | ||
| job = kwargs.get("job") | ||
| if only_if_max_retries_reached and (job and job.retry < job.max_retries): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if only_if_max_retries_reached and (job and job.retry < job.max_retries): | |
| if only_if_max_retries_reached and job and job.retry < job.max_retries: |
6e3a7d9 to
c035a4c
Compare
| try: | ||
| controller._try_perform_job(self.env, job) | ||
| with patch( | ||
| "odoo.addons.test_queue_job.models.test_models.QueueJob" | ||
| ".testing_error_handler" | ||
| ) as patched: | ||
| patched.assert_called_once() | ||
| except Exception: | ||
| _logger.info("Job fails") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that lines 361-365 are not executed. Test has to be improved here, I believe.
Extract of the log on CI:
2025-01-14 05:40:08,895 275 INFO odoo odoo.addons.test_queue_job.tests.test_job: Starting TestJobsOnTestingMethod.test_failed_job_perform ...
2025-01-14 05:40:08,903 275 INFO odoo odoo.addons.queue_job.job: Job 648616de-b28e-4d33-8c3f-5be7ac760cac fails due to , execute <bound method QueueJob.testing_error_handler of queue.job()>
2025-01-14 05:40:08,903 275 INFO odoo odoo.addons.test_queue_job.tests.test_job: Job fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trisdoan @nilshamerlinck ping :)
queue_job/models/queue_job.py
Outdated
| if random.random() <= failure_rate: | ||
| raise JobError("Job failed") | ||
|
|
||
| def _call_webhook(self, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we have to handle this here. If you provide your own handler you can do whatever you want, including calling a webhook. I'd drop this part.
queue_job/job.py
Outdated
| ) | ||
| action = getattr(record, funcname) | ||
| _logger.info("Job %s fails due to %s, execute %s", self.uuid, exc, action) | ||
| action_kwargs = {**self.job_config.error_handler_kwargs, "job": self} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
job should be the 1st positional argument IMO
c035a4c to
4db7635
Compare
|
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
No description provided.